package com.zang.blogz.enmus;

import cn.hutool.core.util.StrUtil;
import io.github.vampireachao.stream.core.stream.Steam;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.function.Predicate;

/**
 * @author ZVerify
 * @since 2022/10/11 14:21
 **/
@AllArgsConstructor
@Getter
public enum SearchModeEnum {

    /**
     * mysql
     */
    MYSQL("mysql", "mySqlSearchStrategyImpl"),
    /**
     * elasticsearch
     */
    ELASTICSEARCH("elasticsearch", "esSearchStrategyImpl");

    /**
     * 模式
     */
    private final String mode;

    /**
     * 策略
     */
    private final String strategy;

    /**
     * 获取策略
     * @param mode 模式
     * @return {@link String} 搜索策略
     */
    public static String getStrategy(String mode){

        return Steam.of(SearchModeEnum.values()).findFirst(strategy(mode)).orElse(MYSQL).getStrategy();

    }

    public static Predicate<? super SearchModeEnum> strategy(String mode){

        return val->  StrUtil.equals(val.getMode(), mode);
    }
}
